﻿using Direct.IDAL.User.Jurisdiction;
using DirectSell.Model.User;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DirectSell.DAL.User.Jurisdiction
{
    /// <summary>
    /// 会员登录仓储类
    /// </summary>
    public class LoginRepository :AbsRepository, ILoginRepository
    {

        #region 初始化数据--郭文昊--2018年10月28日18:34:37
        public LoginRepository():base("UserInforMations")
        {

        }
        #endregion

        #region 验证登录信息是否正确--郭文昊--2018年10月28日18:36:17
        /// <summary>
        /// 验证登录信息是否正确
        /// </summary>
        /// <param name="Account">账号</param>
        /// <param name="Number"></param>
        /// <returns></returns>
        public async Task<bool> CheckInformation(UserLoginInfo info)
        {
            var sql = new StringBuilder().Append(" SELECT COUNT(*)  FROM UserInforMations ")
                .AppendFormat(" WHERE UserCode ='{0}' OR Phone = '{0}' AND UserPassWord='{1}'", info.Account,info.PassWord);
            long result = await base.QueryCount<long>(sql.ToString());
            return result > 0; 
        }
        #endregion

        #region 查询该用户信息--郭文昊--2018年10月29日00:43:22
        /// <summary>
        /// 查询该用户信息
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public async Task<UserInforMationDetails> GetInfo(UserLoginInfo info)
        {
            var sql = new StringBuilder().Append(" SELECT *  FROM UserInforMations ")
               .AppendFormat(" WHERE UserCode ='{0}' OR Phone = '{0}' ", info.Account);
            var model =  await base.QueryAsync<UserInforMationDetails>(sql.ToString());
            return model.FirstOrDefault();
        }
        #endregion

    }
}
